package com.educate.educms.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import com.educate.commonutils.ResultOne;
import com.educate.educms.entity.CrmBanner;
import com.educate.educms.service.CrmBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前台banner
 * </p>
 *
 * @author educate.wht
 * @since 2022-08-23
 */
@RestController
@RequestMapping("/educms/bannerfront")
@CrossOrigin
public class BannerFrontController {
    @Autowired
    private CrmBannerService crmBannerService;
    //查询所有得banner
    @GetMapping("getAllBanner")
    public ResultOne getAllBanner(){
        //根据id进行降序排列,显示排列之后前两条记录
        QueryWrapper<CrmBanner> queryWrapper=new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        //last方法,拼接sql语句
        queryWrapper.last("limit 2");
        List<CrmBanner> list=crmBannerService.selectAllBanner();
        return ResultOne.ok().data("list",list);
    }
}
